package message;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

import javax.jms.*;
import java.util.Enumeration;

/**
 * Created with Intel IDEA.
 * 连接的元数据
 * @Auther: gjt
 * @Date: 2024/11/3 15:47
 */
public class ConnectionMetaDataA {
    private static String USERNAME = ActiveMQConnection.DEFAULT_USER;
    private static String PASSWORD = ActiveMQConnection.DEFAULT_PASSWORD;
    private static String BROKER = ActiveMQConnection.DEFAULT_BROKER_URL;
    private QueueConnection qConnect = null;
    private QueueSession qSession = null;
    private Queue responseQ = null;
    private Queue requestQ = null;

    public ConnectionMetaDataA(String queuecf, String requestQueue, String responseQueue) throws Exception {
        QueueConnectionFactory conFactory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER);
        qConnect = conFactory.createQueueConnection();

        // 创建会话
        qSession = qConnect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        // 创建请求队列|响应队列
        requestQ = new ActiveMQQueue(requestQueue);
        responseQ = new ActiveMQQueue(responseQueue);

        // 创建完成，启动链接
        qConnect.start();
    }

    public void getDate() throws JMSException {
        ConnectionMetaData metaData = qConnect.getMetaData();
        System.out.println("version " + metaData.getJMSVersion() + "." + metaData.getJMSMajorVersion());
        System.out.println("Provider: " + metaData.getJMSProviderName());
        Enumeration jmsxPropertyNames = metaData.getJMSXPropertyNames();

        while (jmsxPropertyNames.hasMoreElements()) {
            String name = (String) jmsxPropertyNames.nextElement();
            System.out.println("JMSX property: " + name);
        }
    }
}
